
@extends('layouts.default')

@section('title', '')

@push('scripts')
<script>
    var userId = "{{auth()->id()}}"
    layui.use(['layer', 'element','form','table','laypage','laytpl','laydate'], function(){
        var layer = layui.layer;
        var form = layui.form;
        var element = layui.element;
        var table = layui.table;
        var laypage = layui.laypage;
        var laytpl = layui.laytpl;
        var laydate = layui.laydate;
        var param = {};


        getList(1);
        renderSelect();

        //日期时间范围
        laydate.render({
            elem: '#test10'
            ,type: 'date'
            ,range: true
        });

        //下拉框初始化
        function renderSelect(){
            getDictionaryItem({'diccode': ['award_type','LEVEL','award_grade']}, function (res){
                if(res.code === 1) {
                    let data = res.data;
                    for(var k in data) {
                        if(k == 'hdjb'){
                            $('[data-role='+k+'List]').empty().append('<option value="">请选择</option>');
                        }else{
                            $('[data-role='+k+'List]').empty().append('<option value="">请选择</option>');
                        }
                        let d = data[k];
                        for (var i in d) {
                            $('[data-role='+k+'List]').append('<option value="' + d[i].optionId + '">' + d[i].selectValue + '</option>');
                        }
                    }
                    form.render();
                }
            });
            getTermData({},function(res){
                if(res.code == 1){
                    $('select[name=data_version_id]').empty();
                    $('select[name=data_version_id]').append('<option value="">请选择</option>');
                    for(var i in res.data){
                        $('select[name=data_version_id]').append('<option value="'+res.data[i].id+'">'+res.data[i].title+'</option>');
                    }
                    form.render();
                }
            })
        }

        // 查询
        form.on('submit(queryBtn)', function(data) {
            Object.assign(param, {
                    "search": data.field
            });
            getList(1);
            return false;
        });

        // 导出
        form.on('submit(exportBtn)', function(data) {
            Object.assign(param, {
                    "search": data.field
            });
            exportAwards(param,function(res){
                if(res.code == '1'){
                    exportsDel('获奖情况.xlsx','/download/excel/'+res.data.file_name);
                }else{
                    layer.msg(res.msg, {icon: 5,shift : 6});
                }
            });
            return false;
        });

        //导出excel
        function exportsDel(showName,fileName){
            window.location.href = "{{route('download.FileDownloadDel')}}"+'?filename='+showName+'&file_url='+fileName;
        }

        //重置
        $('button[type=reset]').click(function(){
            $('#search-form')[0].reset();
            $('button[lay-filter=queryBtn]').click();
            return false;
        })

        function getList(page){
            Object.assign(param,{"page":page});
            getAwardsList(param,function(res){
                if(res.code == 1){
                    table.render({
                        elem: '#tablelist'
                        ,toolbar: '#toolbarDemo'
                        ,defaultToolbar:[]
                        ,data: res.data.data
                        ,limit:res.data.limit
                        ,skin:'nob'
                        ,even:true
                        //,cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
                        ,cols: [[
                        {field: '', title: '学年学期',width:'10%',align:'center',templet: function(d) {
                            // return (page-1)*res.data.limit+d.LAY_INDEX;
                            if(d.data_version_name === null){
                                return '';
                            }else{
                                return d.data_version_name;
                            }
                        }}
                        ,{field: '', title: '类型',width:'10%',align:'center',templet: function(d) {
                            if(d.category_array.length>0){
                                if(d.category_array[0]['optionId'] == 150){
                                    return '各类指导奖（学生）';
                                }else{
                                    return d.category_array[0].selectValue;
                                }
                            }else{
                                return '';
                            }
                       }}
                        ,{field: 'name', title: '名称',width:'10%',align:'center'}
                        ,{field: 'begin_date', title: '获奖日期',width:'10%',align:'center'}
                        // ,{field: 'end_date', title: '结束日期',width:'10%',align:'center'}
                        ,{field: '', title: '级别',width:'5%',align:'center',templet: function(d) {
                            if(d.level_array.length>0){
                                return d.level_array[0].selectValue;
                            }else{
                                return '';
                            }
                       }}
                       ,{field: '', title: '等级',width:'5%',align:'center',templet: function(d) {
                            if(d.grade_array.length>0){
                                return d.grade_array[0].selectValue;
                            }else{
                                return '';
                            }
                       }}
                       ,{field: 'nickname', title: '创建人',width:'10%',align:'center'}
                       ,{field: '', title: '状态',width:'8%',align:'center',templet: function(d) {
                            if(d.status == 'FILL_IN'){
                                return '未提交';
                            }else if(d.status == 'REVIEW'){
                                return '待审核';
                            }else if(d.status == 'REVIEW_FAIL'){
                                return '已驳回';
                            }else if(d.status == 'PASS'){
                                return '审核通过';
                            }else{
                                return '-';
                            }

                       }}
                        ,{field: '', title: '操作',toolbar: '#barDemo',width:'',align:'center'}
                        ]],
                        done: function(res, curr, count) {
                            setBtnPermission();
                            curr_page = page;
                        },
                    });

                    $('#pageBar').empty();
                    if(res.data.total >0){
                        //分页
                        laypage.render({
                        elem: 'pageBar' //注意，这里的 test1 是 ID，不用加 # 号
                        ,count: [res.data.total] //数据总数，从服务端得到
                        ,curr: page
                        ,layout: ['limit', 'count', 'prev', 'page', 'next',  'skip']
                        ,limit:res.data.limit
                        ,jump: function(obj, first) {
                                //首次不执行
                                if (!first) {
                                    Object.assign(param,{"limit":obj.limit});
                                    getList(obj.curr)
                                }
                            }
                        });
                    }
                     setBtnPermission();
                }else {
                    layer.msg(res.msg, {icon: 5});
                }

            })
        }



        table.on('tool(tablelist)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）

            if(layEvent === 'del'){ //删除
                layer.confirm('确定删除吗?', function(index){
                    delAwards({'id':data.id},function(res){
                        if(res.code == '1'){
                            layer.msg(res.msg,{icon: 6,time: 1000});
                            obj.del();
                            layer.close(index);
                        }else{
                            layer.msg(res.msg, {icon: 5,shift : 6});
                        }
                    })


                });
            }else if(layEvent === 'edit'){
              window.location.href = "{{route('awards.wards.add')}}?id="+data.id;

            }else if(layEvent === 'check'){
                window.location.href = "{{route('awards.wards.check')}}?id="+data.id;

            }else if(layEvent === 'see'){
                window.location.href = "{{route('awards.wards.see')}}?id="+data.id;
            }else if(layEvent === 'push'){
                layer.confirm('确定此处理吗?', function(index){
                    dealAwardsPush({'id':data.id},function(res){
                        if(res.code == '1'){
                            layer.msg(res.msg,{icon: 6,time: 1000});
                            getList(curr_page)
                            layer.close(index);
                        }else{
                            layer.msg(res.msg, {icon: 5,shift : 6});
                        }
                    })


                });
            }
        });


    })
</script>


<script type="text/html" id="barDemo">
    @if(auth()->user()->cur_role_id == 2)
        @{{# if((d.status == 'FILL_IN' || d.status == 'REVIEW_FAIL') && userId==d.creator_id){ }}
        <a class="layui-btn layui-btn-primary layui-border-blue layui-btn-xs" lay-event="edit"  btnPermission="177">编辑</a>
        @{{# }else{ }}
        <a class="layui-btn layui-btn-primary layui-border-blue layui-btn-xs layui-btn-disabled" lay-event=""  btnPermission="177">编辑</a>
        @{{# } }}
    @else
        <a class="layui-btn layui-btn-primary layui-border-blue layui-btn-xs" lay-event="edit"  btnPermission="177">编辑</a>
    @endif

    <a class="layui-btn layui-btn-primary layui-border-blue layui-btn-xs" lay-event="see"  btnPermission="179">查看</a>
    @{{# if(d.status == 'REVIEW'){ }}
    <a class="layui-btn layui-btn-primary layui-border-blue layui-btn-xs" lay-event="check"  btnPermission="178">审核</a>
    @{{# }else{ }}
    <a class="layui-btn layui-btn-primary layui-border-blue layui-btn-xs layui-btn-disabled" lay-event=""  btnPermission="178">审核</a>
    @{{# } }}

    <a btnPermission="53" class="layui-btn push layui-btn-primary layui-btn-xs @{{# if(d.status == 'PASS'){ }} layui-border-blue@{{# }else{ }}layui-btn-disabled @{{# } }}"  @{{# if(d.status=='PASS'){ }}lay-event="push"@{{# } }}  >
        @{{# if(d.is_push == '1'){ }}取消推优@{{# }else{}}推优@{{# } }}</a>

    @if(auth()->user()->cur_role_id == 2)
    @{{# if((d.status == 'FILL_IN' || d.status == 'REVIEW_FAIL') && userId==d.creator_id){ }}
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="del" btnPermission="180">删除</a>
    @{{# }else{ }}
    <a class="layui-btn layui-btn-primary layui-btn-xs layui-btn-disabled" lay-event="" btnPermission="180">删除</a>
    @{{# } }}
    @else
        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="del" btnPermission="180">删除</a>
    @endif

</script>
<!---头部工具栏--->
<script type="text/html" id="toolbarDemo">

    <div class="list-head">
            <h3>获奖情况列表</h3>
            <div class="layui-btn-container list-opt-btns">
                <a btnPermission="176" class="layui-btn layui-btn-normal" href="{{route('awards.wards.add')}}" id="addBtn"> + 新增 </a>
            </div>
        </div>
</script>

@endpush

@section('content')
    <style>
         /* .layui-table-body{
            overflow: hidden;
        }  */
    </style>
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-row">
                <form class="layui-form" id="search-form" >
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label" >学年学期:</label>
                            <div class="layui-input-inline">
                                <select name="data_version_id" class="layui-select" lay-filter="term_id" data-role="term_id" style="width:190px;"></select>
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label" >类型:</label>
                            <div class="layui-input-inline">
                                <select data-role="award_typeList" name="category"   lay-filter="" ></select>
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label" >名称:</label>
                            <div class="layui-input-inline">
                                <input autocomplete="off" type="text" name="name" class="layui-input" placeholder="请输入">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label" >创建人:</label>
                            <div class="layui-input-inline">
                                <input autocomplete="off" type="text" name="nickname" class="layui-input" placeholder="请输入">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label" >级别:</label>
                            <div class="layui-input-inline">
                                <select data-role="LEVELList" name="level"   lay-filter="" ></select>
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label" >等级:</label>
                            <div class="layui-input-inline">
                                <select data-role="award_gradeList" name="grade"   lay-filter="" ></select>
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label" >状态:</label>
                            <div class="layui-input-inline">
                                <select data-role="" name="status"   lay-filter="" >
                                    <option value="">请选择</option>
                                    <option value="FILL_IN">未提交</option>
                                    <option value="REVIEW">待审核</option>
                                    <option value="REVIEW_FAIL">已驳回</option>
                                    <option value="PASS">审核通过</option>
                                </select>
                            </div>
                        </div>

                        <div class="layui-inline" >
                                <button lay-submit id="queryBtn" class="pear-btn pear-btn-md pear-btn-primary" lay-filter="queryBtn" >
                                    查询
                                </button>
                                <button type="reset" class="pear-btn pear-btn-md reset">
                                    重置
                                </button>
                                <button lay-submit id="exportBtn" class="pear-btn pear-btn-md pear-btn-primary" lay-filter="exportBtn" btnPermission="332">
                                    导出
                                </button>
                        </div>
                    </div>



                </form>
            </div>
        </div>
    </div>


    <div class="layui-card">

        <div class="layui-card-body">
            <table class="layui-table" id="tablelist" lay-filter="tablelist" ></table>
            <div class="pagebarbox" style="text-align: end"><div id="pageBar" class="pagebar"></div></div>
        </div>
    </div>


@endsection
